package com.loveofsoftware.fotolab.gestures;

import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.widget.Toast;

import com.loveofsoftware.fotolab.EffectActivity;

public class AdvancedGestureDetector extends SimpleOnGestureListener {
	
	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		System.out.println("Single Tap Up touch detected");
		mActivity.toggleMode();	
		return true;
	}

	@Override
	public boolean onDown(MotionEvent e) {
		switch (e.getPointerCount()) {
		case 2:
			System.out.println("2 touch detected");
			mActivity.toggleMode();	
			return true;			

		default:
			break;
		}
		return super.onDown(e);
	}

	private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_MAX_OFF_PATH = 250;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;

    EffectActivity mActivity = null;
    
    public void init(EffectActivity activity) {
    	mActivity = activity;
    }
    
//    @Override
//    public boolean onDoubleTap (MotionEvent e){    	
//    	System.out.println("Detected a double tap");
//    	mActivity.showSliders();
//    	return false;
//    }

	@Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//        try {
//        	System.out.println("Detected fling");
//            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
//                return false;
//            // right to left swipe
//            if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//                Toast.makeText(mActivity, "Left Swipe", Toast.LENGTH_SHORT).show();
//            }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//                Toast.makeText(mActivity, "Right Swipe", Toast.LENGTH_SHORT).show();
//            }
//        } catch (Exception e) {
//            // nothing
//        }
		return false;
    }

}
